<?php


namespace app\auth\controller;


use app\auth\service\LoginService;
use app\BaseController;
use think\facade\Lang;
use think\facade\View;

class Login extends BaseController
{
    /**
     * 登录
     * @return string
     */
    public function index() {
        return View::fetch('login',[
            'langType' => cookie('system_lang')
        ]);
    }

    /**
     * 登录操作
     */
    public function doLogin() {
        if($this->request->isPost()) {
            $params = $this->request->post();
            $res = LoginService::login($params['userName'],$params['password'],$params['code']);
            return $res;
        }
    }

    /**
     * 声场验证码
     * @return \think\Response
     */
    public function verify() {
        return \captcha();
    }

    public function loginOut() {
        session('admin',null);
        return View::fetch('login',[
            'langType' => cookie('system_lang')
        ]);
    }

    public function setLang() {
        $params = $this->request->post();
        cookie('system_lang',$params['langType']);
        return ['code' => 0,'msg' => '操作成功'];
    }


}